#Alexander F. Gazmararian
#afg2@princeton.edu
#January 9, 2024

#Purpose: Plot the share of community members with people in their network who are involved in fossil fuels

#Load packages
library(tidyverse)
library(here)
library(stringr)
library(scales)

#Load data, which have been processed to include relevant variables
# Survey data part of: Gazmararian, A.F. 2023. Geographic Mobility, Social Identity, and Self-Interest.
mobile_sub <- readRDS(here("data", "inter", "fairsurveys", "fairsurvey_2022.rds"))
mobile_sub <- subset(mobile_sub, select = c(weights, ffprox))
# Survey data part of: https://www.sciencedirect.com/science/article/pii/S0301421523004652
#Gazmararian, A.F., 2024. Fossil fuel communities support climate policy coupled with just transition assistance. Energy Policy, 184, p.113880.
trans_sub <- readRDS(here("data", "inter", "fairsurveys", "fairsurvey_2021.rds"))
trans_sub <- subset(trans_sub, select = c(weights, prox))

#subset to relevant question
trans_sub$sample <- "2021"
names(mobile_sub)[2] <- "prox"
mobile_sub$sample <- "2022"
g <- rbind(trans_sub, mobile_sub)
#Figure M1
weights.plot <- g %>%
  ggplot() +
  geom_bar(aes(x=prox,y=after_stat(prop),weight=weights))+
  geom_bar(aes(x=prox,y=after_stat(prop)),color="red",fill="transparent") +
  scale_x_continuous(breaks = seq(0,10,1)) +
  theme_bw(base_size = 14) +
  labs(
    x = str_wrap(
      "Among the 10 people you know best in your community, roughly how many work in coal, oil or gas?", 55),
    y=""
  ) +
  scale_y_continuous(labels = percent) +
  theme(panel.grid = element_blank())
ggsave(
  weights.plot,
  filename = here("output", "figures", "si_fig_M1_community_weights.png"),
  dpi = 300,
  width = 6.5,
  height = 3,
  scale = 1.5
  )
